package com.xgg.taiwuinfo.filter.fc;

import android.content.Context;
import android.util.Log;

import com.xgg.taiwuinfo.filter.FC_EqualSelect;
import com.xgg.taiwuinfo.filter.FilterComponent;
import com.xgg.taiwuinfo.gongfa.abilities.Ability_Cuipo_Body;
import com.xgg.taiwuinfo.gongfa.base.Gongfa;
import com.xgg.taiwuinfo.gongfa.base.Gongfa_Cuipo;
import com.xgg.taiwuinfo.utils.GongfaType;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class FCCuipoBodyEqualSelect extends FC_EqualSelect {

    public FCCuipoBodyEqualSelect(JSONObject obj)
    {
        mTypeId = FilterComponent.FT_CUIPOBODY_EQUAL_SELECT;
        if (obj != null) {
            try {
                ReadValue = obj.getInt("v");
                ReadCompare = obj.getInt("c");
            } catch (Exception e) {
                Log.d("LoadJson", e.getLocalizedMessage());
                ReadValue = 0;
                ReadCompare = FC_EQUAL;
            }
        }
        else {
            ReadValue = 0;
            ReadCompare = FC_EQUAL;
        }
        TempValue = ReadValue;
        TempCompare = ReadCompare;

        FieldStr = "攻击部位";
        if (mValueMap == null) {
            mValueMap = new ArrayList<>();

            AddMap(mValueMap , "躯干"  , "0");
            AddMap(mValueMap , "躯干-胸背"  , "1");
            AddMap(mValueMap , "躯干-腰腹"  , "2");
            AddMap(mValueMap , "躯干-头颈"  , "3");
            AddMap(mValueMap , "四肢"  , "4");
            AddMap(mValueMap , "四肢-左右臂"  , "5");
            AddMap(mValueMap , "四肢-左右腿"  , "6");
            AddMap(mValueMap , "心神"  , "7");
            AddMap(mValueMap , "毒质"  , "8");
            AddMap(mValueMap , "全身"  , "9");
        }

        if (mCompareMap == null)
        {
            mCompareMap = new ArrayList<>();
        }
        else
        {
            mCompareMap.clear();
            AddMap(mCompareMap , "是", FC_EQUAL + "");
        }
    }

    @Override
    public String FilterGongfa(Gongfa gongfa){
        if ((gongfa.mType & GongfaType.TYPE_CUIPO ) == 0)
            return null;
        Ability_Cuipo_Body body = ((Gongfa_Cuipo)gongfa).ability_cuipo_body;
        if (ReadValue == 0)     //主要攻击躯干
        {
            if (body.getTorso() > 0 && body.getLimbs() == 0)
                return "攻击躯干";
        }
        else if (ReadValue == 1)        //主要攻击胸背
        {
            if (body.Chest > 0 && body.Waist == 0)
                return "攻击胸背";
        }
        else if (ReadValue == 2)        //主要攻击腰腹
        {
            if (body.Chest == 0 && body.Waist > 0)
                return "攻击腰腹";
        }
        else if (ReadValue == 3)        //主要攻击头
        {
            if (body.Head == body.getTorso())
                return "攻击头颈";
        }
        else if (ReadValue == 4)        //主要攻击四肢
        {
            if (body.getTorso() == 0 && body.getLimbs() > 0)
                return "攻击四肢";
        }
        else if (ReadValue == 5)        //主要攻击手臂
        {
            if (body.LHand + body.RHand == body.getLimbs())
                return "攻击左右臂";
        }
        else if (ReadValue == 6)        //主要攻击腿
        {
            if (body.LLeg + body.RLeg == body.getLimbs())
                return "攻击左右腿";
        }
        else if (ReadValue == 7)        //主要攻击心神
        {
            if (body.Spirit > 0)
                return "攻击心神";
        }
        else if (ReadValue == 8)        //主要攻击毒质
        {
            if (body.Poison > 0)
                return "攻击毒质";
        }
        else if (ReadValue == 9)        //主要攻击全身
        {
            if (body.Whole > 0)
                return "攻击全身";
        }
        return null;
    }

    @Override
    public List<Map<String, String>> getFieldString(Context ctx){
        List<Map<String, String>> mCompMap = new ArrayList<>();
        Map<String, String> map;

        map = new HashMap<>();
        map.put("f", FieldStr);
        map.put("v",   "0");
        mCompMap.add(map);

        return mCompMap;
    }

    @Override
    public List<Map<String, String>> getValueMap(Context ctx)
    {
        return mValueMap;
    }



}
